package storm.irccyn.e4.rcp.wizard.parts;
import grammar.*;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.Persist;
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import programme.GUI.JConsole;

import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
import org.eclipse.ui.console.TextConsoleViewer;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.osgi.framework.console.*;
public class consoleStorm extends ViewPart {

	private Text txtInput;
	private TableViewer tableViewer;
	JConsole Controle;
	 private Text text;
	@Inject
	private MDirtyable dirty;

	@PostConstruct
	public void createComposite(Composite parent) {
		//parent.setLayout(new GridLayout(1, false));

		/*txtInput = new Text(parent, SWT.BORDER);
		txtInput.setMessage("Enter text to mark part as dirty");
		txtInput.addModifyListener(new ModifyListener() {
			@Override
			public void modifyText(ModifyEvent e) {
				dirty.setDirty(true);
			}
		});
		txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		tableViewer = new TableViewer(parent);

		tableViewer.add("Sample item 1");
		tableViewer.add("Sample item 2");
		
		tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));*/
        //JConsole Controle = new JConsole("",20,60);
        //Display display = new Display();
       // Shell shell = new Shell(display);
        //shell.setLayout(new FillLayout());
	/*	txtInput = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
		txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL|GridData.FILL_VERTICAL));
		*/
		
		
		/* MessageConsole myConsole = new MessageConsole("Console", null); // declare console

		ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ 
		myConsole});

		MessageConsoleStream stream = myConsole.newMessageStream();

		PrintStream myS = new PrintStream(stream);
		System.setOut(myS); // link standard output stream to the console
		System.setErr(myS); // link error output stream to the console
		TextConsoleViewer textConsoleViewer = new TextConsoleViewer(parent, myConsole);   
*/
	/*	text = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
		text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL|GridData.FILL_VERTICAL));

		  OutputStream out = new OutputStream() {
		   @Override
		   public void write(int b) throws IOException {
		    if (text.isDisposed()) return;
		    text.append(String.valueOf((char) b));
		   }
		  };
		  final PrintStream oldOut = System.out;
		  System.setOut(new PrintStream(out));
		  text.addDisposeListener(new DisposeListener() {
		   public void widgetDisposed(DisposeEvent e) {
		    System.setOut(oldOut);
		   }
		  });*/
		
        new TextConsoleViewer(parent, ConsoleViewManager.getConsole("maconsole"));

		/*   final Canvas clock = new Canvas(parent,SWT.NONE);
	        clock.addPaintListener(new PaintListener() {
	          public void paintControl(PaintEvent e) {
	            e.gc.drawArc(e.x,e.y,e.width-1,e.height-1,0,360);
	          } });*/
     
	      
	
	}

	@Focus
	public void setFocus() {
		//tableViewer.getTable().setFocus();
	}

	@Persist
	public void save() {
		//dirty.setDirty(false);
	}

	@Override
	public void createPartControl(Composite parent) {
		// TODO Auto-generated method stub
		
	}
	
	
}
